home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dirut / fichici.zip / FICHICI.C next >
Text File  |  1993-06-29  |  5KB  |  156 lines

  1. /*  *************  FICHICI 1.0
  2.  *  fichici.c   Checks the specified pathname for a file with the
  3.  *              current date.
  4.  *                        ******************************
  5.  *                        **   (c) Dave Vernest       **
  6.  *                        **  Arts Computing Office   **
  7.  *                        **  University of Waterloo  **
  8.  *                        **      June 23, 1993       **
  9.  *                        ******************************
  10.  *              Compiled in Borland Turbo C 2.0
  11.  *
  12.  *              SYNTAX:
  13.  *                       fichici <PATHNAME>
  14.  * SYSTEM DOCS:
  15.  *      First the system date is obtained. Then files in the specified
  16.  *      path are accessed one by one, and their dates compared
  17.  *      with the system date.
  18.  *      If there is a match, ERRORLEVEL returns 0.
  19.  *      Otherwise,           ERRORLEVEL returns 1.
  20.  */
  21.  #include <dir.h>       /* ref by findfirst */
  22.  #include <io.h>        /* ref by getftime */
  23.  #include <dos.h>       /* ref by getdate */
  24.  #include <sys\stat.h>  /* ref by bit ops */
  25.  
  26. /* function prototypes */
  27. void error_checking(int argc,char **argv);
  28. void user_help();
  29. void sysdate(struct date *sys_info);
  30. int  compare_dates(struct date sys_info, struct ffblk file_info);
  31.  
  32. int main(int argc,char **argv)   {
  33.     struct date sys_info;       /* holds system dates */
  34.     struct ffblk file_info;     /* holds file info */
  35.     char pathname[50];          /* directory being searched */
  36.     int filegone=0,             /* returns 0 if not eof */
  37.     found=0,                /* returns 0 if a file with today's
  38.                       date is found */
  39.     errorlevel=0;           /* returns 0 if a file is found, 1 if not */
  40.  
  41.    error_checking(argc,argv);
  42.  
  43.    sysdate(&sys_info);          /* gets system date */
  44.  
  45.    strupr(argv[1]);             /* convert pathname to upper-case */
  46.    filegone=findfirst(argv[1],&file_info,0);  /* finds first file */
  47.  
  48.    found=compare_dates(sys_info,file_info);
  49.  
  50.    while (!filegone)   {
  51.     if (found==0) {
  52.             break;      /* if found, break out of loop */
  53.     }
  54.  
  55.      filegone=findnext(&file_info);
  56.     found=compare_dates(sys_info,file_info);
  57.    }
  58.  
  59.    if (found==0) {
  60.         return (errorlevel=0);
  61.     }
  62.         else {
  63.         return (errorlevel=1);
  64.    }
  65. }     /* end main */
  66.  
  67.  
  68. void error_checking(int argc,char **argv) {
  69.     char *drive="",
  70.          *dir="",
  71.          *name="",
  72.          *ext="";
  73.     int path_test;
  74.  
  75.     if (!(argc==2)) {
  76.         user_help();
  77.         exit(1);
  78.     }
  79. /* fnsplit return flags defined in dir.h
  80.  * #define WILDCARDS 0x01
  81.  * #define EXTENSION 0x02
  82.  * #define FILENAME  0x04
  83.  * #define DIRECTORY 0x08
  84.  * #define DRIVE     0x10
  85.  */
  86.     path_test=fnsplit(argv[1],drive,dir,name,ext);
  87.     if (!(path_test & DRIVE)) {
  88.             printf("ERROR: Pathname must include drive.\n");
  89.             exit(1);
  90.     }
  91.  
  92.     if ( !(path_test & FILENAME)  &&
  93.          !(path_test & WILDCARDS)) {
  94.             printf("ERROR: Pathname must include filename or wildcards\n");
  95.             exit(1);
  96.     }
  97.  
  98.     }
  99. void user_help() {
  100.  
  101. char *help;
  102.  
  103. help= "*************  FICHICI 1.0          FILEDATE CHECKING UTILITY\n"
  104. "                                    \n"
  105. "              ******************************        \n"
  106. "              **   (c) Dave Vernest       **            \n"
  107. "              **  Arts Computing Office   **            \n"
  108. "              **  University of Waterloo  **            \n"
  109. "              **      June 23, 1993       **            \n"
  110. "              ******************************            \n"
  111. "                                                                   \n"
  112. "SYNTAX                                                             \n"
  113. "    fichici PATHNAME                                            \n"
  114. "\n"
  115. "    ex. fichici C:\USER\TMP\*.*                                 \n"
  116. "                                                                   \n"
  117. "DESCRIPTION                                                        \n"
  118. "    This is a file that searches the specified pathname for files\n"
  119. "    matching the current system date. This utility is designed to be\n"
  120. "    used in a DOS batch file, hence the returning errorcodes. \n"
  121. "                                                                 \n"
  122. "    Files in the specified path are accessed one by one, and their\n"
  123. "    dates compared with the system date.                            \n"
  124. "    If there is a match, ERRORLEVEL returns 0.                      \n"
  125. "    Otherwise,           ERRORLEVEL returns 1.                      \n";
  126. system("cls");
  127. printf("%s",help);
  128. }
  129.  
  130. int compare_dates(struct date sys_info, struct ffblk file_info) {
  131.    int file_day,
  132.        file_month,  /* date info for files */
  133.        file_year;
  134.  
  135.    /* Values for converted from bit form to integer form:
  136.     * for file_year below
  137.     * 111111100000000 --mask for year comparison (0xfe00)
  138.     * 000100000000000 --for year 1988
  139.     * 000100000000000 --result
  140.     * 0001000 (/512)  --chops off low-order bits (shift)
  141.     */
  142.    file_day  =(0x001f & file_info.ff_fdate)/1;
  143.    file_month=(0x01e0 & file_info.ff_fdate)/32;
  144.    file_year=((0xfe00 & file_info.ff_fdate)/512) + 1980;
  145.    /* ff_fdate measures years since 1980, therefore 1980 must be added
  146.     * to get a full year value
  147.     */
  148.    return !(((sys_info.da_day==file_day) &&     /* returns 0 if file date */
  149.          (sys_info.da_mon==file_month) &&   /* matches system date */
  150.          (sys_info.da_year==file_year)));
  151. }
  152.  
  153. void sysdate(struct date *tmp_info) {
  154.     getdate(tmp_info);
  155. }
  156.